fix: escape user-controlled category/description before innerHTML inj… - #1670
Conversation
|
@akshara200829-lgtm is attempting to deploy a commit to the Anuj's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
The failing/cancelled checks (3.10, 3.11, 3.12) are unrelated to this PR. The actual failure is a pre-existing test collection error in AttributeError: module 'validation' has no attribute 'get_choice' This occurs in |
|
🎉 Thank you for your contribution! Your Pull Request has been merged successfully. |
📝 Description
Fixes unsanitized innerHTML usage in the Budget Tracker, where user-supplied custom category and description values were interpolated directly into template strings without escaping — allowing arbitrary HTML/JS to execute in the browser (self-XSS), and persist across reloads via localStorage.
Added an escapeHTML() helper that converts a string into safe, literal text using the browser's own DOM serialization (via textContent → innerHTML round-trip). Applied it to the two places where user input reaches innerHTML:
renderTransactions() — escapes t.category and t.description
renderBreakdown() — escapes cat (the category name used in the breakdown label)
Note: populateCategories() (the categorySelect.innerHTML dropdown) was left unchanged — it's built only from the static BUDGET_CATEGORIES constant, not user input, so it wasn't actually affected by this vulnerability.
Tested: injecting the payload above into both the custom category field and the description field, confirmed no script execution in the transaction list or breakdown panel, and confirmed it stays inert after a page reload (localStorage round-trip).
🔗 Linked Issue
Closes #1583
📋 Contribution Checklist